﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Globalization;

namespace AnonsaiWPF.CSharp
{
    /// <summary>
    /// Interaction logic for Overview.xaml
    /// </summary>
    public partial class Overview : Window, IWindow
    {
        public Overview()
        {
            InitializeComponent();
            this.CultureInfoBox.Items.Add("en-US");
            this.CultureInfoBox.Items.Add("en-GB");
            this.CultureInfoBox.Items.Add("he-IL");
            this.CultureInfoBox.Items.Add("fr-FR");
            this.CultureInfoBox.Items.Add("de-DE");
            this.CultureInfoBox.SelectionChanged += new SelectionChangedEventHandler(CultureInfoBox_SelectionChanged);

            this.MinHeight = 520;
            this.MinWidth = 750;           
        }

        public Grid Root
        {
            get
            {
                return this.RootVisual;
            }
        }

        public void SetTheme()
        {
        }
  
        public void DetachContent()
        {
            RemoveLogicalChild(Content);
        }

        void CultureInfoBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CultureInfo info = new CultureInfo(this.CultureInfoBox.SelectedItem.ToString());
           
            this.PercentageEditor.CultureInfo = info;
            this.CurrencyEditor.CultureInfo = info;
            this.NumberEditor.CultureInfo = info;
            this.FixedPointEditor.CultureInfo = info;
        }

        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            long res;

            if (String.IsNullOrEmpty(this.NumberBox.Text))
            {
                return;
            }

            if (Int64.TryParse(this.NumberBox.Text, out res))
            {
                if (res < 11)
                {
                    this.NumberEditor.DecimalPlaces = (int)res;
                    this.CurrencyEditor.DecimalPlaces = (int)res;
                    this.PercentageEditor.DecimalPlaces = (int)res;
                    this.FixedPointEditor.DecimalPlaces = (int)res;
                }
                else
                {
                    this.NumberBox.Text = "";
                }
            }
            else
            {
                this.NumberBox.Text = "";
            }

        }

        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (this.None == null)
                return;

            if (this.None.IsChecked.Value)
            {
                this.NumberEditor.SpinType = VIBlend.WPF.Controls.SpinType.None;
                this.CurrencyEditor.SpinType = VIBlend.WPF.Controls.SpinType.None;
                this.PercentageEditor.SpinType = VIBlend.WPF.Controls.SpinType.None;
                this.FixedPointEditor.SpinType = VIBlend.WPF.Controls.SpinType.None;
                this.DecimalEditor.SpinType = VIBlend.WPF.Controls.SpinType.None;
            }
            else if (this.Digit.IsChecked.Value)
            {
                this.NumberEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigit;
                this.CurrencyEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigit;
                this.PercentageEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigit;
                this.FixedPointEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigit;
                this.DecimalEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigit;

            }
            else if (this.DigitWithWrap.IsChecked.Value)
            {
                this.NumberEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigitWithWrap;
                this.CurrencyEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigitWithWrap;
                this.PercentageEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigitWithWrap;
                this.FixedPointEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigitWithWrap;
                this.DecimalEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinDigitWithWrap;

            }
            else if (this.ValueBeforeDigit.IsChecked.Value)
            {
                this.NumberEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinValueBeforeDigit;
                this.CurrencyEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinValueBeforeDigit;
                this.PercentageEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinValueBeforeDigit;
                this.FixedPointEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinValueBeforeDigit;
                this.DecimalEditor.SpinType = VIBlend.WPF.Controls.SpinType.SpinValueBeforeDigit;
            }
        }
    }
}
